import WellAnalysis from '@/api/v3/mechanical.js'

export async function getWinch(params) {
  console.log('params', params);
  const res = await Promise.all([
    WellAnalysis.getTension(params),
    WellAnalysis.getStrain(params),
    WellAnalysis.getDescent(params),
    WellAnalysis.getCable(params),
    WellAnalysis.getSafeData(params),
  ])
  console.log("getWinch.all", res);
  // 绞车操作表数据
  const winchOperations = [];
  let startwinch = res[0][0]; //起始状态(从井底开始)
  let beforeWinch = startwinch //暂存startwinch的点
  res[0].forEach((item, index) => {
    //隔150米等分
    if (startwinch.depth - item.depth >= 150 ||
      item.depth == res[2].f_descent_hel_depth ||
      item.depth == res[0][0].depth ||
      res[0][0].depth - item.depth == params.calculate_space) {

      beforeWinch = startwinch
      startwinch = item;
      if (params.is_Not_metric == false) {// 英制单位
        winchOperations.push({
          depth: startwinch.depth,
          floor100WeaknessHighValue: (startwinch.F_weak_high * 0.2248).toFixed(2), // 磅
          floor100WeaknessLowValue: (startwinch.F_weak_low * 0.2248).toFixed(2),
          floor75WeaknessValue: (startwinch.F_weak_rate_low * 0.2248).toFixed(2),
          floorLiftedTension: (startwinch.F_pull * 0.2248).toFixed(2),
          floorLoweredTension: (startwinch.F_push * 0.2248).toFixed(2),
          cableDownwardStretched: res[1][index].all_strain_push,
          cableLiftedStretched: res[1][index].all_strain_pull,
          cableHeadLiftedTension: (res[3][index].F_pull * 0.2248).toFixed(2),
          cableHeadLoweredTension: (res[3][index].F_push * 0.2248).toFixed(2),
        });
      } else {//公制单位
        winchOperations.push({
          depth: startwinch.depth,
          floor100WeaknessHighValue: (startwinch.F_weak_high / 1000).toFixed(2), // KN
          floor100WeaknessLowValue: (startwinch.F_weak_low / 1000).toFixed(2),
          floor75WeaknessValue: (startwinch.F_weak_rate_low / 1000).toFixed(2),
          floorLiftedTension: (startwinch.F_pull / 1000).toFixed(2),
          floorLoweredTension: (startwinch.F_push / 1000).toFixed(2),
          cableDownwardStretched: res[1][index].all_strain_push,
          cableLiftedStretched: res[1][index].all_strain_pull,
          cableHeadLiftedTension: (res[3][index].F_pull / 1000).toFixed(2),
          cableHeadLoweredTension: (res[3][index].F_push / 1000).toFixed(2),
        });
      }

      // 等于下入深度时，还原回上一个点
      if (item.depth == res[2].f_descent_hel_depth && beforeWinch.depth - res[2].f_descent_hel_depth != 150) {
        startwinch = beforeWinch
      }
    }
  });
  res[4].forEach((item, index) => {
    if (item.depth == winchOperations[index].depth) {
      if (params.is_Not_metric == false) {
        winchOperations[index].safeTension = (item.Q_final * 0.2248).toFixed(2) //磅
      } else {
        winchOperations[index].safeTension = (item.Q_final / 1000).toFixed(2) //kN
      }
    }
  });
  winchOperations.sort((a, b) => a.depth - b.depth); //排序
  console.log("winchOperations", winchOperations);

  return winchOperations
}